package org.btik.light.mobile.common.handler.nbi;

import android.view.View;
import org.btik.light.mobile.common.handler.DevBinder;
import org.btik.light.mobile.meta.mo.DefaultDevMo;
import org.btik.light.tool.ByteUtil;

import java.util.function.BiConsumer;

/**
 * @author lustre
 * @since 2023/4/30 18:00
 */
public class NbiSpeedController implements BiConsumer<Integer, View>, DevBinder {
    private final RawNbiCommand rawNbiCommand;

    public NbiSpeedController(byte[] rawCommand) {
        rawNbiCommand = new RawNbiCommand(rawCommand);
    }

    @Override
    public void accept(Integer integer, View view) {
        if (integer == null) {
            return;
        }
        byte[] buf = new byte[]{' ', ' ', ' '};
        byte[] encode = rawNbiCommand.encode();
        ByteUtil.getChars(integer, 3, buf);
        encode[29] = buf[0];
        encode[30] = buf[1];
        encode[31] = buf[2];

        NbiAgent.send(rawNbiCommand);


    }

    @Override
    public void bind(DefaultDevMo devMo) {
        rawNbiCommand.setTarget(devMo.getSn());
    }
}
